import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-12-17
 * Time: 12:13
 */
public class test2 {
    /*
    NewCoder  BM47  寻找第K大
     */
    public int findKth (int[] nums, int n, int k) {
        // write code here
        PriorityQueue<Integer> q = new PriorityQueue<>((o1,o2) -> o1.compareTo(o2));
        for(int num:nums){
            if(q.size()<k){
                q.add(num);
            }else{
                if(q.peek()<num){
                    q.poll();
                    q.add(num);
                }
            }
        }
        return q.isEmpty()?0:q.peek();
    }
}
